package com.maserb.monitor.entity.card;

import lombok.Data;

import javax.smartcardio.Card;
import java.util.ArrayList;
import java.util.List;

@Deprecated
@Data
public class CardPackageEntity {
    private CardPackageHeaderEntity header;
    private String commandCode;
    private Integer total;
    private List<CardRecordEntity> records;

    public static CardPackageEntity convert(String sequence) {
        Box<Integer> index = new Box<Integer>();
        index.setValue(0);
        CardPackageEntity entity = new CardPackageEntity();
        entity.setHeader(CardPackageHeaderEntity.convert(sequence, index));
        entity.setCommandCode(CardUtils.get(sequence, index, 2));
        entity.setTotal(Integer.valueOf(CardUtils.get(sequence, index, 2)));
        entity.records = new ArrayList<>();
        for (int i = 0; i < entity.getTotal(); i++) {
            CardRecordEntity record = CardRecordEntity.convert(sequence, index);
            entity.records.add(record);
        }

        return entity;
    }
}
